class UserController < ApplicationController
  #用户登录
  def login
    if request.post?
      session[:user_id]=nil
      pwd=Digest::MD5.hexdigest params[:user][:pwd]
      user=User.find_by_name_and_pwd params[:user][:name],pwd
      if user
        session[:user_id]=user.id
        if session[:before_login]
#          puts "================#{session[:before_login]}"
          redirect_to session[:before_login]
        else
          redirect_to :controller => :blogs,:action=>:index
        end
      end
    end
  end

  def logout
    session[:user_id]=nil
    redirect_to "/"
  end

end
